package engine.control
{
	import engine.data.BindManage;
	import engine.data.ModelLocator;
	import engine.data.RoleVo;
	import engine.scene.SceneChangeManager;
	import engine.tip.TipsMainLogic;
	import engine.ui.lite.BaseUI;
	
	import flash.display.DisplayObjectContainer;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.Capabilities;
	import flash.text.TextField;
	
	import newx.StageInfo;
	import newx.com.ResManager;
	
	/**
	 *进度条 
	 * @author yanghr
	 * 
	 */	
	public class MiniLoadingBar extends Sprite
	{
		private static var _self:MiniLoadingBar;
		public static function getInstance():MiniLoadingBar
		{
			if(_self==null)
			{
				_self=new MiniLoadingBar(new privaceClass);
			}
			return _self;
		}
		public function MiniLoadingBar(p:privaceClass)
		{
			init()
		}
		private var _main:Sprite;
		private var _bind:BindManage;
		private var _model:ModelLocator
		private var _role:RoleVo;
		private var _tip:TipsMainLogic;
		private var _maskShap:Shape=new Shape;
		private function  init():void
		{
			_main=ResManager.newResClass("mainLoadingbar") as Sprite;
			addChild(_main);
			_maskShap.graphics.beginFill(0x000000,1);
			_maskShap.graphics.drawRect(-Capabilities.screenResolutionX/2,-Capabilities.screenResolutionY/2,
				Capabilities.screenResolutionX*2,Capabilities.screenResolutionY*2);
			_maskShap.graphics.endFill();
			_maskShap.alpha = 0
			//			MainUIManager.getInstance().downPlace.addChild(sprite);
			this.addChildAt(_maskShap,0)
				
			_bind=BindManage.getInstance();
			_model=ModelLocator.getInstance();
			_role=_model.scene.Role;
			_tip=TipsMainLogic.instance;
		}
		private var _autoHide:Boolean=true;
		/**
		 *是否在进度>=1的时候自动隐藏掉 （默认为true）
		 * @param value
		 * 
		 */		
		public function set autoHide(value:Boolean):void
		{
			_autoHide=value;
		}
		/**
		 *黑色遮罩 
		 * @param enable
		 * 
		 */		
		public function set darkmask(visible:Boolean):void
		{
			_maskShap.visible=visible;
			//			sprite.parent.setChildIndex(sprite,sprite.parent.numChildren-1);
		}
		/**
		 *0<=value<=1 
		 * @param value
		 * 
		 */		
		public function set progress(value:Number):void
		{
			_main["loadingLine"].width=MaxLen*value;
			(_main["txt_3"] as TextField).text=value*100+"%";
			if(value>=1&&_autoHide)
			{
				close()
			}
			else if(!visible)
			{
				show();
			}
			
		}
		private function get MaxLen():Number
		{
			return _main["loadingLineBack"].width-10;
		}
		/**
		 *显示主函数 
		 * @param title 标题内容
		 * @param space 显示的父容器
		 * 
		 */		
		public function show(title:String="",space:DisplayObjectContainer=null):void
		{
			if(space)
				space.addChild(this);
			else
				StageInfo.stage.addChild(this);
			if(title)
				this.title=title;
			this.visible=true;
			darkmask=true;
			resetPos();
		}
		/**
		 *设置标题 
		 * @param title
		 * 
		 */		
		public function set title(title:String):void
		{
			_main["txt_2"].htmlText=title
		}
		/**
		 *关闭主函数 
		 * @param args
		 * 
		 */		
		public function close(...args):void
		{
			progress	=	0;
			this.visible=false;
		}
		private function resetPos():void
		{
			_main.x=( StageInfo.stage.stageWidth -_main.width )/2;
			_main.y=( StageInfo.stage.stageHeight-_main.height)/2;
		}
	}
}
class privaceClass
{
	
}